<?php

	require("DBops.php");
	session_start();
	$ID=$_GET['id'];
	//echo $_SERVER['DOCUMENT_ROOT'];
	if(isset($_POST['submit']))
	{
		$file=$_FILES['file'];
		//echo $_FILES['myfile']['name'];
		if($file['name']==null)
		{
			echo "<script>alert(\"Please select a file!\");</script>";
			echo"1111";
		}
		else
		{
		//echo $file['name'];
			if(!move_uploaded_file($file['tmp_name'], './'.basename($file['name'])))   
			{
				echo $file['error'];
			}
			else
			{
				
				$con = connect("localhost", "root", "", "lab");			
				$sql = "update personalinfo set image='"."./".basename($file['name'])."' where ID = $ID";
				mysql_query($sql, $con);
				//update($con, "personalinfo", "image", './'.basename($file['name']));
				//echo "file upload succeed!";
				//echo "<script>alert(\"file upload succeed!\");</script>";
				echo"<script>location.href='Photo.php?id=$ID'</script>";
			}
		}

	}
	
?>